home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / DATATYPE.SWG / 0014_Large Arrays.pas < prev    next >
Pascal/Delphi Source File  |  1994-01-27  |  2KB  |  101 lines

  1. {
  2. > In a program I am writing I need to create a very large array to store
  3. > infomation in I need an array[1..4096] of string and turbo pascal will
  4.  
  5. Try my unit. My unit uses a TEMSStream to store the information.
  6. Look at the demo how to store your 4096 strings.
  7. }
  8.  
  9. (* Unit LongArray - large arrays in EMS
  10.    PUBLIC DOMAIN  1993 by Holger Daehre 2:248/317.88
  11.    Running: TP 6.0 or above. *)
  12.  
  13. Unit LongArr;
  14.  
  15. Interface
  16.  
  17. Uses  Objects;
  18.  
  19. Var
  20.    Lo_element,ElementSize:LongInt;
  21.  
  22. (* Create_Array creates  Array[Low..High] of Size *)
  23. Procedure Create_Array(Var ps:pStream;Low,High,Size:LongInt);
  24.  
  25. (* Read_Array loads one element from INDEX into Buf *)
  26. Procedure Read_Array(Var ps:pStream;Index:LongInt;Var Buf);
  27.  
  28. (* Write_Array stores the information of Buf in Index *)
  29. Procedure Write_Array(Var ps:pStream;Index:LongInt;Var Buf);
  30.  
  31. (* Dispose_Array releases the allocated EMS memory *)
  32. Procedure Dispose_Array(Var ps:pStream);
  33.  
  34. Implementation
  35.  
  36. Procedure Create_Array(Var ps:pStream;Low,High,Size:LongInt);
  37. Var
  38.    Elements,ArraySize:LongInt;
  39. Begin
  40.    Lo_element:=Low;
  41.    Elements:=High-Low+1;
  42.    ArraySize:=Elements * Size;
  43.    ElementSize:=Size;
  44.    ps := New(pEMSStream, Init(ArraySize,ArraySize));
  45.    If ps^.status <> stOk Then
  46.     Begin
  47.       Dispose(ps, Done);
  48.       ps := NIL;
  49.     End;
  50. End;
  51.  
  52. Procedure Read_Array(Var ps:pStream;Index:LongInt;Var Buf);
  53. Begin
  54.  If ps<>nil Then
  55.  Begin
  56.   ps^.Seek((Index-Lo_element)*ElementSize);
  57.   ps^.Read(Buf,ElementSize);
  58.  End;
  59. End;
  60.  
  61. Procedure Write_Array(Var ps:pStream;Index:LongInt;Var Buf);
  62. Begin
  63.  If ps<>nil Then
  64.  Begin
  65.   ps^.Seek((Index-Lo_element)*ElementSize);
  66.   ps^.Write(Buf,ElementSize);
  67.  End;
  68. End;
  69.  
  70. procedure Dispose_Array(Var ps:pStream);
  71. Begin
  72.  Dispose(ps,Done);
  73.  ps:=NIL;
  74. End;
  75.  
  76. End.
  77.  
  78.  
  79.  
  80.  
  81. Program LongArrayDemo;
  82. Uses Objects,LongArr;
  83. Var MyArr:PStream;
  84.     S:String;
  85.     I:Word;
  86. Begin
  87.   Create_Array(MyArr,0,4096,SizeOf(String));
  88.   If MyArr=nil Then
  89.   Begin
  90.    WriteLn('Couldn''t create array in EMS');
  91.    Halt;
  92.   End;
  93.   S:='This is a TEST !';
  94.   For I:=0 To 4096 Do  Write_Array(MyArr,I,S);
  95.   s:='';
  96.   Randomize;
  97.   Read_Array(MyArr,Random(4096),S);
  98.   WriteLn(S);
  99.   Dispose_Array(MyArr);
  100. End.
  101.